package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.Yybb;
import cn.stylefeng.guns.sys.modular.system.mapper.YybbMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.YybbParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyDywhResult;
import cn.stylefeng.guns.sys.modular.system.model.result.YybbResult;
import  cn.stylefeng.guns.sys.modular.system.service.YybbService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuy
 * @since 2021-04-21
 */
@Service
public class YybbServiceImpl extends ServiceImpl<YybbMapper, Yybb> implements YybbService {

    @Override
    public void add(YybbParam param){
        Yybb entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(YybbParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(YybbParam param){
        Yybb oldEntity = getOldEntity(param);
        Yybb newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public YybbResult findBySpec(YybbParam param){
        return null;
    }

    @Override
    public List<YybbResult> findListBySpec(YybbParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(YybbParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<YybbResult> xjsjList(String time) {
        return baseMapper.xjsjList(time);
    }

    @Override
    public List<BtyDywhResult> dyWhList(Integer state) {
        return baseMapper.dyWhList(state);
    }

    private Serializable getKey(YybbParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private Yybb getOldEntity(YybbParam param) {
        return this.getById(getKey(param));
    }

    private Yybb getEntity(YybbParam param) {
        Yybb entity = new Yybb();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
